
package com.yuanmei.model;

import com.yuanmei.common.Utils;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.Map;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import ir.mirrajabi.searchdialog.core.Searchable;

public class StockInfo extends RealmObject implements Searchable {
    @PrimaryKey
    private String tscode;
    public String getTscode() { return this.tscode;}
    public void setTscode(String code) {
        this.tscode = code;
    }

    private String name;
    public String getName() { return this.name;}
    public void setName(String name) {
        this.name = name;
    }

    private String symbol;
    public String getSymbol() { return this.symbol;}
    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    private String area;
    public String getArea() { return this.area;}
    public void setArea(String area) {
        this.area = area;
    }

    private String industry;
    public String getIndustry() { return this.industry;}
    public void setIndustry(String industry) {
        this.industry = industry;
    }

    private String market;
    public String getMarket() { return this.market;}
    public void setMarket(String market) {
        this.market = market;
    }

    private String pinyin;
    public String getPinyin() { return this.pinyin;}
    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    public StockInfo() {
        super();
    }

    public StockInfo(JSONArray stockInfoItem, Map<String, Integer> fieldMap)
            throws JSONException {
        this.tscode = stockInfoItem.getString(fieldMap.get("ts_code"));
        this.symbol = stockInfoItem.getString(fieldMap.get("symbol"));
        this.name = stockInfoItem.getString(fieldMap.get("name"));
        this.pinyin = Utils.getFirstPinyinSpell(name);
        this.area = stockInfoItem.getString(fieldMap.get("area"));
        this.industry = stockInfoItem.getString(fieldMap.get("industry"));
        this.market = stockInfoItem.getString(fieldMap.get("market"));
    }

    @Override
    public String getTitle() {
        return name + " " + pinyin + " " + symbol + " " + industry;
    }
}
